package cn.edu.sjtu.se;

import java.io.FileNotFoundException;
import java.io.PrintStream;

public class Config {

	public static String KEY_DEBUG = "debug";

	public static String KEY_PASV = "pasv";
	public static String KEY_HOST = "host";
	public static String KEY_PORT = "port";
	public static String KEY_USER = "user";
	public static String KEY_PASS = "pass";

	public static String DEFAULT_HOST = "localhost";
	public static int DEFAULT_PORT = 21;
	public static String DEFAULT_USER = "anonymous";
	public static String DEFAULT_PASS = "";

	private String host;
	private Integer port;
	private String user;
	private String pass;
	private boolean pasv;

	public final PrintStream out;
	public final PrintStream err;

	public Config() throws FileNotFoundException {

		host = System.getProperty(KEY_HOST);
		port = Integer.getInteger(KEY_PORT);
		user = System.getProperty(KEY_USER);
		pass = System.getProperty(KEY_PASS);
		pasv = Boolean.getBoolean(KEY_PASV);

		if (Boolean.getBoolean(KEY_DEBUG)) {
			out = System.out;
			err = System.err;
		} else {
			out = new PrintStream("log.txt");
			err = new PrintStream("err.txt");
		}
	}

	public String getHost() {
		return (host == null) ? DEFAULT_HOST : host;
	}

	public int getPort() {
		return (port == null) ? DEFAULT_PORT : port;
	}

	public String getUser() {
		return (user == null) ? DEFAULT_USER : user;
	}

	public String getPass() {
		return (pass == null) ? DEFAULT_PASS : pass;
	}

	public boolean getPasv() {
		return pasv;
	}

}
